using GameFramework;
using GameFramework.ObjectPool;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace LS
{
    public class SpriteReferenceObject : ObjectBase
    {
        private string m_FileName;
        private string m_FileDirectory;

        public string FileName
        {
            get
            {
                return m_FileName;
            }
        }

        public string FileDirectory
        {
            get
            {
                return m_FileDirectory;
            }
        }

        public Sprite SpriteAsset
        {
            get
            {
                return Target as Sprite;
            }
        }

        public SpriteReferenceObject()
        {
            
        }

        public static SpriteReferenceObject Create(string name, Sprite spriteAsset)
        {
            if (spriteAsset == null)
            {
                throw new LSRuntimeException("Sprite asset is invalid.");
            }

            SpriteReferenceObject unitySpriteResourceObject = ReferencePool.Acquire<SpriteReferenceObject>();
            unitySpriteResourceObject.Initialize(name,spriteAsset);
            if (name.Contains("/"))
            {
                unitySpriteResourceObject.m_FileDirectory = Path.GetDirectoryName(name);
                unitySpriteResourceObject.m_FileName = Path.GetFileName(name);
            }
            else
            {
                unitySpriteResourceObject.m_FileName = name;
            }

            return unitySpriteResourceObject;
        }

        protected override void Release(bool isShutdown)
        {
            Sprite.Destroy(SpriteAsset);
        }

        public override void Clear()
        {
            base.Clear();
        }
    }
}
